package com.example.demo;


import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RequestMapping("/message")
@RestController
public class MessageController {

//    定义一个 顺序表表来存储
    List<MessageInfo> messageInfos = new ArrayList<>();

//    获取 list
    @GetMapping("/getList")
    public List<MessageInfo> getList() {
        return messageInfos;
    }


//    存储 list
    @PostMapping(value = "/publish", produces = "application/json")
    public  String publish(@RequestBody() MessageInfo messageInfo) {
        if(StringUtils.hasLength(messageInfo.getMessage()) &&
                StringUtils.hasLength(messageInfo.getTo()) &&
                StringUtils.hasLength(messageInfo.getFrom())) {
            messageInfos.add(messageInfo);
            return "{\"ok\":1}";
        }

        return "{\"ok\":0}";
    }


}
